package com.example.demo.listener;

import com.example.demo.config.FanoutRabbitConfig;
import com.example.demo.config.TopicRabbitConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Description :
 * @Email : zhanchong316@foxmail.com
 * Created by zhanchong on 2019/12/5 11:29
 */
@Component
public class FanoutListener {
    private static Logger logger = LoggerFactory.getLogger(FanoutListener.class);

    @RabbitHandler
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(FanoutRabbitConfig.FANOUT_QUEUE_ONE),
            exchange = @Exchange(value = FanoutRabbitConfig.FANOUT_EXCHANGE, type = ExchangeTypes.FANOUT),
            key = FanoutRabbitConfig.FANOUT_ROUTING_KEY_ONE
    ))
    public void topicOnMessage1(Map message) {
        logger.info("FanoutListener1 received.message:{}", message.toString());
    }

    @RabbitHandler
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(FanoutRabbitConfig.FANOUT_QUEUE_ONE),
            exchange = @Exchange(value = FanoutRabbitConfig.FANOUT_EXCHANGE, type = ExchangeTypes.FANOUT),
            key = FanoutRabbitConfig.FANOUT_ROUTING_KEY_ONE
    ))
    public void topicOnMessage3(Map message) {
        logger.info("FanoutListener3 received.message:{}", message.toString());
    }

    @RabbitHandler
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(FanoutRabbitConfig.FANOUT_QUEUE_TWO),
            exchange = @Exchange(value = FanoutRabbitConfig.FANOUT_EXCHANGE, type = ExchangeTypes.FANOUT),
            key = FanoutRabbitConfig.FANOUT_ROUTING_KEY_TWO
    ))
    public void topicOnMessage2(Map message) {
        logger.info("FanoutListener2 received.message:{}", message.toString());
    }

}
